package com.sudoku.listener;

import java.awt.CardLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;

import com.sudoku.common.Constants;
import com.sudoku.ui.Sudoku;
import com.sudoku.ui.content.SMenu;
import com.sudoku.ui.content.SPanel;

public class ButtonListener implements MouseListener {
	private Sudoku sudoku;
	private String text;
	private JLabel jLabel;
	private int level;
	
	public ButtonListener(Sudoku sudoku, String text, JLabel jLabel, int level) {
		this.sudoku = sudoku;
		this.level = level;
		this.text = text;
		this.jLabel = jLabel;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		sudoku.setPanel(new SPanel(sudoku, this.level));
		sudoku.getCards().add(sudoku.getPanel(), Constants.LABEL_PUZZLE);
		CardLayout cardLayout = (CardLayout)(sudoku.getCards().getLayout());
	
		cardLayout.show(sudoku.getCards(), Constants.LABEL_PUZZLE);
		sudoku.setAtCard(Constants.LABEL_PUZZLE);
		sudoku.setLevel(this.level);
		sudoku.setMenu(new SMenu(sudoku));
	}
	
	@Override
	public void mouseEntered(MouseEvent e) {
		jLabel.setText(text);
		jLabel.setVisible(true);
	}
	
	@Override
	public void mouseExited(MouseEvent e) {
		jLabel.setText("Please Choose Mode of Game!");
	}

	@Override
	public void mousePressed(MouseEvent e) {}
	
	@Override
	public void mouseReleased(MouseEvent e) {}
	
}
